package org.wms.minbearwcs.dao.inbound.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import org.wms.minbearwcs.dao.inbound.inf.InboundOrderDao;
import org.wms.minbearwcs.entity.Mapper.inbound.InboundOrderMapper;
import org.wms.minbearwcs.entity.PO.wcs.inbound.InboundOrder;
import org.wms.minbearwcs.entity.PO.wcs.inbound.status.InboundOrderStatus;

import java.time.LocalDateTime;

@Repository
@RequiredArgsConstructor
public class InboundOrderDaoImpl implements InboundOrderDao {

    private final InboundOrderMapper mapper;

    @Override
    public boolean insert(InboundOrder inboundOrder) {
        return mapper.insert(inboundOrder) == 1;
    }

    @Override
    public boolean updateStatusByInboundOrderCode(String inboundORderCode, InboundOrderStatus status) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(InboundOrder::getInboundOrderCode,inboundORderCode)
                .set(InboundOrder::getStatus,status)
                .update();
    }

    @Override
    public boolean updateStartTimeByInboundOrderCode(String inboundORderCode, LocalDateTime startTime) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(InboundOrder::getInboundOrderCode,inboundORderCode)
                .set(InboundOrder::getStartTime,startTime)
                .update();
    }

    @Override
    public InboundOrder selectByInboundOrderCode(String inboundORderCode) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(InboundOrder::getInboundOrderCode,inboundORderCode)
                .one();
    }

    @Override
    public InboundOrderStatus selectStatusByInboundOrderCode(String inboundOrderCode) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(InboundOrder::getInboundOrderCode,inboundOrderCode)
                .select(InboundOrder::getStatus)
                .one()
                .getStatus();
    }
}
